<!--
 * @Descripttion: 
 * @version: @ 1.0.0
 * @Author: 朱江洲
 * @Date: 2022-04-20 09:34:19
 * @LastEditors: 朱江洲
 * @LastEditTime: 2022-06-01 14:00:07
-->
<template>
  <div>
    <el-dialog
      title="转移负责人"
      :visible.sync="dialog.transferShow"
      width="30%"
      @close="transferClose"
      :modal="false"
    >
      <el-form
        :model="transForm"
        ref="transForm"
        :rules="transRules"
        label-position="top"
        :inline="false"
        size="normal"
      >
        <el-form-item label="变更负责人为" prop="userId">
          <el-select v-model="transForm.userId" placeholder="请选择负责人">
            <el-option
              v-for="item in options"
              :key="item.userId"
              :label="item.nickName"
              :value="item.userId"
            >
            </el-option>
          </el-select>
        </el-form-item>

        <el-form-item>
          <span>将原负责人：</span>
          <div>
            <el-radio v-model="transForm.type" label="1">移出</el-radio>
            <el-radio v-model="transForm.type" label="2">转为团队成员</el-radio>
          </div>
        </el-form-item>
        <div v-if="transForm.type == 2">
          <el-form-item label="权限">
            <el-radio v-model="transForm.readonly" label="0">只读</el-radio>
            <el-radio v-model="transForm.readonly" label="1">读写</el-radio>
          </el-form-item>
          <el-form-item label="有效时间">
            <el-select v-model="transForm.effValue" @change="timeChange">
              <el-option
                v-for="item in effOptions"
                :key="item.value"
                :label="item.label"
                :value="item.value"
              >
              </el-option>
            </el-select>
            <el-date-picker
              v-model="transForm.expire"
              type="date"
              value-format="yyyy-MM-dd"
              placeholder="选择日期"
              v-if="timeShow"
              style="margin-left: 20px"
            >
            </el-date-picker>
          </el-form-item>
        </div>
      </el-form>

      <span slot="footer">
        <el-button @click="dialog.transferShow = false">取消</el-button>
        <el-button type="primary" @click="onSubmit">保存</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import { transfer, transferList } from "@/api/team";
export default {
  props: {
    dialog: {
      type: Object,
      required: true,
    },
    drawerData: {
      type: Object,
      required: true,
    },
    type: {
      type: Number,
      required: true,
    },
  },
  data() {
    return {
      timeShow: false,
      transForm: {
        module: this.type,
        entity: this.drawerData.id,
        userId: null,
        oldUserId: this.drawerData.userId,
        type: "1",
        effValue: 1,
        readonly: "0",
        expire: null,
      },
      transRules: {
        userId: [
          {
            required: true,
            message: "请选择负责人",
            trigger: "change",
          },
        ],
      },
      options: [],
      effOptions: [
        {
          value: 1,
          label: "不限",
        },
        {
          value: 2,
          label: "截止到",
        },
      ],
    };
  },
  created() {
    this.getTransferList();
  },
  methods: {
    // 获取转移列表
    getTransferList() {
      transferList({
        module: this.type,
        entity: this.drawerData.id,
      }).then((res) => {
        this.options = res.data;
      });
    },
    // 关闭
    transferClose() {
      this.dialog.transferShowEject = false;
    },
    // 提交
    onSubmit() {
      transfer(this.transForm).then((res) => {
        this.$message.success(res.msg);
        this.dialog.transferShow = false;
        this.$parent.getList();
      });
    },
    timeChange(val) {
      if (val == 1) {
        this.timeShow = false;
      } else if (val == 2) {
        this.timeShow = true;
      }
    },
  },
};
</script>

<style lang="less" scoped>
</style>